define(["jQuery", "kendo"], function ($, kendo) {
    return {
    	creationMode:false,
		selectedList:false,
		listItemCount:0,
		radioChartVal : false,
		widthChart : 350,
		heightChart : 250,
		btnEnable : false,
		imgIdTemp : false,
		editClick : false,
		charData : [],
		styleChoose : false,
		widthChoose : false,
		rColor : 0,
		gColor : 0,
		bColor : 0,
		isEditClick:0, 
		widthTableLast:false, 
		heightTableLast:false, 
		leftTableLast:false, 
		topTableLast:false, 
		
		show : function(){ 
			var center = App.getAbsoluteCenter();
			center.x -= (Math.floor($( "#initial-table-dragable-menu").width()/2) - $("#rootContainer").offset().left);
			center.y -= (Math.floor($( "#initial-table-dragable-menu").height()/2) - $("#rootContainer").offset().top);
			$( "#initial-table-dragable-menu").css('left', center.x);
			$( "#initial-table-dragable-menu").css('top', center.y);
			
			$( "#initial-table-dragable-menu" ).show();	 	
		},
		
        init: function (e) {
		
			var indxList = false;
			console.log("init chart ..."); 
			// if(App.initialTableToolbox.isEditClick == 0){
				var urlImg = 1; 
				for(widthCount = 1; widthCount <= 5; widthCount++){
					var newWidthContainer = $('<div></div>').attr({'id':"width_"+widthCount,'class':'width_list', 'width_to':urlImg}).appendTo($('.list-value-width'));
					var newImgWidthComponent = $('<img></img>').attr({ 'src': App.baseUrl+"assets/css/line/"+urlImg+"px.png",'id':"imgwidth_"+widthCount}).appendTo(newWidthContainer); 
					newWidthContainer.on('tap click',function(e){  
						
						$('.width_list').css('background-color','');
						$(this).css('background-color','rgb(255, 105, 180)');  
						App.initialTableToolbox.widthChoose = $(this).attr('width_to')+'px';						
					
					});
					urlImg = urlImg * 2; 
				} 
				
				var urlImgStyle = false;
				for(styleCount = 1; styleCount <= 3; styleCount++){
					if(styleCount == 1){
						urlImgStyle = '1px';
					}else if(styleCount == 2){
						urlImgStyle = 'dashed';
					}else if(styleCount == 3){
						urlImgStyle = 'point';
					}
					var newStyleContainer = $('<div></div>').attr({'id':"style_"+styleCount,'class':'style_list', 'style_to':styleCount}).appendTo($('.list-value-style'));
					var newImgStyleComponent = $('<img></img>').attr({ 'src': App.baseUrl+"assets/css/line/"+urlImgStyle+".png",'id':"imgstyle_"+styleCount}).appendTo(newStyleContainer);
					newStyleContainer.on('tap click',function(e){ 
						
							$('.style_list').css('background-color','');
							$(this).css('background-color','rgb(255, 105, 180)');  
							
							if($(this).attr('style_to') == 1){
								App.initialTableToolbox.styleChoose = 'solid';
							}else if($(this).attr('style_to') == 2){
								App.initialTableToolbox.styleChoose = 'dashed';
							}else if($(this).attr('style_to') == 3){
								App.initialTableToolbox.styleChoose = 'dotted';
							}
						// }
					});
					urlImgStyle = urlImgStyle * 2; 
				} 
			$("#initial-table-dragable-menu").draggable();
			$("#initial-table-dragable-menu").hide();
		
			$(".table-tools").click(function() {
				if(!App.toolboxValidation("tool_table_ico"))
				{
					return;
				}
				$(this).addClass('active');
				App.openedTool = $(this);
				App.setEnableTableCreationMode(true); 
			});
			
			$("#button-color-table").click(function() { 
			});
			
			$("#label-color-table").jPicker(
					{
					 window:
						  {
							expandable: true
						  },
						  images:
						  {
							clientPath : App.baseUrl+'assets/css/images/jPicker/'
						  }
					},
					function(color, context)
					{
						var all = color.val('all'); 
						App.initialTableToolbox.rColor = all.r;
						App.initialTableToolbox.gColor = all.g;
						App.initialTableToolbox.bColor = all.b;			
					}
			);
			
			$('#value-column').keyup(function () {
				if(!$.isNumeric($('#value-column').val())) { 
					alert("Only numeric");
					$('#value-column').val("1");
				}else if($.isNumeric($('#value-column').val())){
					if($('#value-column').val() == "" || $('#value-column').val() < 1 || $('#value-column').val() > 10){ 
						$('#value-column').val("1");
						alert(App.localize("%col_range_warning")); 
						return false;
					}
				}
				// $('#value-column').val("1")
			});
			
			$('#value-row').keyup(function () {
				if(!$.isNumeric($('#value-row').val())) { 
					alert("Only numeric");
					$('#value-row').val("1")
				}else if($.isNumeric($('#value-row').val())){
					if($('#value-row').val() == "" || $('#value-row').val() < 1 || $('#value-row').val() > 10){ 
						$('#value-row').val("1");
						alert(App.localize("%col_range_warning")); 
						return false;
					}
				}
				// $('#value-row').val("1")
			});
			
			$(".save-table-button").click(function() {
				$( "#initial-table-dragable-menu" ).hide(); 
				
				App.openedTool.removeClass('active');
				App.openedTool =false;
				
				var totalRowCol = 0;
				App.setEnableTableCreationMode(false,"");
				
				
				
				var rows = new Number($("#value-row").val());
				var cols = new Number($("#value-column").val());
				
				if(rows == "" || rows < 1 || rows > 10){
					totalRowCol = 1;
					alert(App.localize("%row_range_warning")); 
					return false;
				}else if(cols == "" || cols < 1 || cols > 10){
					totalRowCol = 1;
					alert(App.localize("%col_range_warning")); 
					return false;
				}
				
				$('.width_list').css('background-color','');
				if(totalRowCol == 0){
					if(App.isTableEdit == 1){  
						App.updateTableProperty(rows,cols,App.initialTableToolbox.leftTableLast,App.initialTableToolbox.topTableLast);
						App.isTableEdit = 0;
					}
					else
					{
						var center = App.getAbsoluteCenter();
						App.addTableToServer(rows,cols,center.x-275,center.y-187); 
					}
				}
			 
			});
			 
			
			 
			$(".cancel-table-button").click(function() {
				var r=confirm(App.localize("%cancel_confirmation"));
				if (r==true)
				{ 
					$( "#initial-table-dragable-menu" ).hide(); 
					App.setEnableTableCreationMode(false,"");
						
					App.openedTool.removeClass('active');
					App.openedTool =false;
					//hide any color picker windows if shown.
					$('.jPicker.Container').each(function(){
						if($(this).css('display') == 'block')
						{	
							$(this).css('display','none');
						}
					});
				}
				
			});	

			$(".row-add-button").click(function() {
				var rowSize = $("#value-row").val();
				if(rowSize == "" || rowSize == 10){
					alert(App.localize("%val_range_warning"));
				}else{
					rowSize++;
					$("#value-row").val(rowSize);
				}
			});
			
			$(".row-min-button").click(function() {
				var rowSize = $("#value-row").val();
				if(rowSize == "" || rowSize == 1){
					alert(App.localize("%val_range_warning"));
				}else{
					rowSize--;
					$("#value-row").val(rowSize);
				}
			});
			
			$(".column-add-button").click(function() {
				var colSize = $("#value-column").val();
				if(colSize == "" || colSize == 10){
					alert(App.localize("%val_range_warning"));
				}else{
					colSize++;
					$("#value-column").val(colSize);
				}
			});
			
			$(".column-min-button").click(function() {
				var colSize = $("#value-column").val();
				if(colSize == "" || colSize == 1){
					alert(App.localize("%val_range_warning"));
				}else{
					colSize--;
					$("#value-column").val(colSize);
				}
			});
		} 
		 
	}	
});